package zyh.struts2.action;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class UploadAction extends ActionSupport{
    private String title;
    private File upload;
    private String uploadContentType;
    private String uploadFileName;
    @Override
    public String execute() throws Exception {
        String path=ServletActionContext.getServletContext().getRealPath("/upload");
        File newFile=new File(path);
        try {
            FileUtils.copyFile(upload,new File(newFile,uploadFileName));
        }
        catch (IOException e){
            e.printStackTrace();
        }
        System.out.println(path);
        System.out.println(uploadContentType);
        System.out.println(uploadFileName);
        return SUCCESS;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public File getUpload() {
        return upload;
    }

    public void setUpload(File upload) {
        this.upload = upload;
    }

    public String getUploadContentType() {
        return uploadContentType;
    }

    public void setUploadContentType(String uploadContentType) {
        this.uploadContentType = uploadContentType;
    }

    public String getUploadFileName() {
        return uploadFileName;
    }

    public void setUploadFileName(String uploadFileName) {
        this.uploadFileName = uploadFileName;
    }

}
